package com.yupi.springbootinit.utils;


import com.yupi.springbootinit.es.entity.ChatSession;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.search.SearchHit;

import java.util.ArrayList;
import java.util.List;

public class EsToBeanUtils {
    public static List<ChatSession> parseSearchResponse(SearchResponse searchResponse) {
        SearchHit[] hits = searchResponse.getHits().getHits();
        List<ChatSession> chatSessions = new ArrayList<>();
        for (SearchHit hit : hits) {
            ChatSession chatSession = new ChatSession();
            chatSessions.add( chatSession.fromMap(hit.getSourceAsMap()));
        }
        return chatSessions;
    }
}
